<template>
  <div>
    <div style="display: flex;align-items: center;justify-content: center;">
      <el-card style="width: 80%;margin-top: 30px">
        <div style="margin-bottom: 10px;margin-left:5px;font-size: 20px;font-weight: bold;">查看参与活动的酒店</div>
        <div style="margin-bottom: 20px">
        </div>
        <el-table ref="userTable" :data="tableData" stripe
                  :header-cell-style="{backgroundColor:'aliceblue',color:'#666'}">
          <el-table-column prop="id" label="序号" align="center"></el-table-column>
          <el-table-column prop="hotel_id" label="图片">
            <template v-slot="scope">
              <div style="display: flex;align-items: center">
                <el-image style="width: 50px;height: 50px;border-radius: 50%" v-if="scope.row.hotel_id"
                          :src="`http://localhost:8000/hotel_image_download/${scope.row.hotel_id}/`"
                          :preview-src-list="[scope.row.hotel_id]"></el-image>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="hotelname" label="酒店"></el-table-column>
          <el-table-column prop="location" label="地址"></el-table-column>
          <el-table-column prop="level" label="等级"></el-table-column>
          <el-table-column prop="min_price" label="最低价"></el-table-column>
          <el-table-column label="操作" width="200%" align="center">
            <template v-slot="scope">
              <el-button size="mini" type="danger" plain @click="fail(scope.row.id)">删除酒店</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div style="margin: 10px 0">
          <el-pagination
              @current-change="handleCurrentChange"
              :current-page="page_id"
              :page-sizes="[100, 200, 300, 400]"
              :page-size="page_size"
              layout="total,  prev, pager, next"
              :total="page_total">
          </el-pagination>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
export default {
  name: "hotelactive",
  data() {
    return {
      user: JSON.parse(localStorage.getItem('user') || '{}'),
      tableData: [],
      page_id: 1,//当前的页码
      page_size: 5,//每页显示的个数
      page_total: 0,
    }
  },
  methods: {
    fail(id) {
      this.$request.post('/activity_delete/', {
            "activity_id": id,
          }
      ).then(res => {
        if (res.code === '200') {
          this.$message.success("删除成功")
          // 刷新页面
          // 延迟一秒后调用加载表数据的函数
          setTimeout(() => {
            window.location.reload();
          }, 1000);
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    load(page_id) {  //分页查询
      if (page_id) this.page_id = page_id
      this.$request.post('/activity_list/', {
            "page_id": this.page_id,
            "page_size": this.page_size,
          }
      ).then(res => {
        if (res.code === '200') {
          this.tableData = res.data.activity_list
          this.page_total = res.data.item_amount
          console.log("查询酒店详情", res.data)
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    handleCurrentChange(page_id) {//下一页
      this.load(page_id)
    },
  },
  created() {
    this.load()
  }
}
</script>

<style scoped>

</style>